package com.zxc.ompz;

import net.rim.device.api.system.Characters;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.component.ObjectListField;
import net.rim.device.api.ui.container.FullScreen;

public class LogScreen extends FullScreen {
	private ObjectListField listLog;
	private String[] logs;
	private int n;
	public LogScreen() {
		super(FullScreen.VERTICAL_SCROLL|FullScreen.VERTICAL_SCROLLBAR|Screen.DEFAULT_CLOSE);
		logs = new String[]{};
		listLog = new ObjectListField();
		Font font = Font.getDefault().derive(Font.PLAIN, 18);
		listLog.set(logs);
		listLog.setFont(font);
		listLog.setRowHeight(font.getHeight());
		n = Display.getHeight()/listLog.getRowHeight();
		add(listLog);
	}
	public void addLog(String log) {
		listLog.insert(listLog.getSize(), log);
	}
	
	protected boolean keyChar(char key, int status, int time){
		switch (key){
		case Characters.LATIN_CAPITAL_LETTER_T:
		case Characters.LATIN_SMALL_LETTER_T:
			listLog.setSelectedIndex(0);
			break;
		case Characters.LATIN_CAPITAL_LETTER_B:
		case Characters.LATIN_SMALL_LETTER_B:
			listLog.setSelectedIndex(listLog.getSize()-1);
			break;
		case Characters.SPACE:
			listLog.setSelectedIndex(listLog.getSelectedIndex()+n-1);
			break;
		}
		return false;
	}
}
